/**
 * Created by mac on 2017/7/31.
 */
var OK='本王知道了';
var TITLE_ERR = '系統提示';
var TITLE_OK = '操作完成！';
var BTN_OK='確 定';
Zepto(function(){
    var Onav = document.getElementsByTagName("nav")[0];
    var Oliu = document.getElementsByClassName("liu")[0];
    var Onav_h = Onav.offsetHeight;
    Oliu.style.height = Onav_h+"px";
    Oliu.style.display = "block";
})
function _Err(msg){
    lclose();
    f=(arguments.length==2)?arguments[1]:'';
    layer.open({type:1,style:'background:none;width:99%;',shadeClose:false,content:msg,end:function(){
        if(typeof(f)=='function') eval(f).call(this);
    }});
}
function _Msg(msg){
    lclose();
    f=(arguments.length==2)?arguments[1]:'';
    layer.open({type:1,style:'background:none;width:99%',time:2,content:msg,end:function(){
        if(typeof(f)=='function') eval(f).call(this);
    }});
}
function _Toast(msg){
    noPop=true;
    layer.open({style:'bottom:10%;text-align:center;',content:msg,skin:'msg',shade:'background-color: rgba(0,0,0,.2)',time:2,end:function(){noPop=false;}});
}
function _Tip(msg,f){
    noPop=true;
    if(msg=='') msg='加載中，请稍候';
    if(typeof(f)=='number') times=f;else times=1;
    layer.open({type:2,content:msg,shade:'background-color:rgba(0,0,0,.3)',shadeClose:false,time:times,end:function(){ noPop=false;if(typeof(f)=='function') eval(f).call(this); }});
}
function _pPage(){
    _Tip();
    args = arguments.length;
    url = arguments[0];
    _func = arguments[1];
    $.post(url,function(d){
        if(d.status==1){
            if(args==2 && typeof(_func)=='function') eval(_func).call(this,d,url);
            else document.location.href=url;
        }else{
            noPop=true;
            switch(d.error){
                case '-100':msg='請先登錄系統！';break;
                case '-101':msg='請先完善手機號碼！';break;
            }
            if(args==2 && typeof(_func)=='function') eval(_func).call(this,d,url);
            else popLogin(1,url);
        }
    },'json');
}
function _gPage(url){
    _Tip();
    document.location.href=url
}
function popLogin(){
    noPop=true;
    te = arguments[0]?arguments[0]:1;
    url = arguments[1]?arguments[1]:'/Index';
    follow = arguments[2]?arguments[2]:true;
    $.get('/Index/popLogin',{type:te,redirect:url,follow:follow},function(data){
        layer.open({style:'background:none;width:100%',content:data,shadeClose:false,end:function(){} });
    });
}
function popPerfect(){
    $.get('/Members/perfectData',function(data){
        _Err(data);
    });
}
function lclose(){
    layer.closeAll();
}
function doSubmitPhoneform(){
    $.post('/Members/updatePhone',$("#_phoneform").serialize(),function(data){
        if(data.status==1) {lclose();_Err(data.content);}
        else $("#_error").html(data.error);
    },'json');
}
oValue='';
function getValidateCode(){
    cT = parseInt($("#getValidate").html());
    if(isNaN(cT)) {oValue=$("#getValidate").html();$("#getValidate").html('120');cT=120;}
    else {$("#_error").html('請稍候再試');return false;}
    $.post('/Index/smsValidate',{phone:$("#phone").val()},function(data){
        if(data.status==1){
            $("#_error").html('手機碼驗證已發送。');
            timeoutProcess = setInterval(function(){
                console.log(cT+"|"+oValue);
                if(--cT <= 0) {
                    clearTimeout(timeoutProcess);
                    $("#getValidate").html(oValue);
                }else $("#getValidate").html(cT);
            }, 1000);
        }else {$("#_error").html(data.error);$("#getValidate").html(oValue);}
    },'json');
}
function doSubmitLogin(){
    noPop=true
    $.post('/Index/login',$("#login_form2").serialize(),function(data){
        if(data.status==1){
            layer.open({content:'<div style="color:#fff;">登入成功，請稍候…</div>',style:'border:none;background-color:#323232;',time:1,end:function(){
                if(data.follow==true) parent.document.location.href=data.url;
                else parent.document.location.reload();
            } });
        }else $("#_error").html(data.error);
    },'json');
}
function is_weixin() {
    var ua = navigator.userAgent.toLowerCase();
    return (ua.match(/MicroMessenger/i) == "micromessenger") ;
}

//交易记录以及持仓订单展开及缩起
function show_display(event){
    if($(event).siblings("ol").height() == 0){
        $(event).siblings("ol").animate({"height":"auto"},1000);
        $(event).css({"transition":"all 1s","transform":"rotate(180deg)"});
        $(event).siblings("p:nth-of-type(2)").css({"display":"block"});
        $(event).siblings("p:nth-of-type(3)").css({"display":"block"});
    }else {
        $(event).siblings("ol").animate({"height":0},1000);
        $(event).css({"transition":"all 1s","transform":"rotate(360deg)"});
        $(event).siblings("p:nth-of-type(2)").css({"display":"none"});
        $(event).siblings("p:nth-of-type(3)").css({"display":"none"});
    }
};/**
 * Created by zeteng on 2017/6/20.
 */
Zepto(function(){
    $(".load_content ul li").click(function(){
        $(this).addClass("current").siblings().removeClass("current");
        var index = $(this).index();
        $(".load_content>div").eq(index).css({"display":"block"}).siblings(".load_content>div").css({"display":"none"});
    });
    $(".xieyi b").click(function(){
        $(this).addClass("current");
    });
});